package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.pojo.SysDtArea;
import cn.cs.service.SysDtAreaService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sysDtArea")
public class SysDtAreaController {
    @Resource
    private SysDtAreaService sysDtAreaService;
    /*
    * 获取省接口
    * */
    @RequestMapping("/p/getProvince")
    @ResponseBody
    public Dto getProvince(HttpServletRequest request) {
        Dto dto=new Dto();
        Map<String,Object> map =new HashMap<String,Object>();
        map.put("areaLevel",1);
        try {
            List<SysDtArea> list  =sysDtAreaService.getSysDtAreaListByMap(map);
            dto.setData(list);
            dto.setSuccess("true");
            dto.setErrorCode("0");
        } catch (Exception e) {
            dto.setSuccess("false");
            dto.setMsg("查询失败");
            dto.setErrorCode("0002");
            e.printStackTrace();
        }
        return dto;

    }
    /*
    * 获取市县接口
    * */
    @RequestMapping("/p/getSysDtAreasByParId")
    @ResponseBody
    public Dto getCity(String id) {
        Dto dto=new Dto();
        try {
           List<SysDtArea> list  =sysDtAreaService.getSysDtAreasByParId(id);
            dto.setData(list);
            dto.setSuccess("true");
            dto.setErrorCode("0");
        } catch (Exception e) {
            dto.setSuccess("false");
            dto.setMsg("查询失败");
            dto.setErrorCode("0002");
            e.printStackTrace();
        }
        return dto;

    }
}
